/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package controller.Actions;

import java.util.Enumeration;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model.User;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author Adriano
 */
public class LogoutAction extends Action {

    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
        try {
            User u = (User) request.getSession().getAttribute("User");
            if (u == null) {

                return mapping.findForward("erroAlias");
            } else {
                Enumeration en = request.getSession().getAttributeNames();
                while (en.hasMoreElements()) {
                    request.getSession().removeAttribute(en.nextElement().toString());
                }
                return mapping.findForward("loginAlias");
            }
        } catch (Exception e) {
            return mapping.findForward("erroAlias");
        }

    }

}
